import bcrypt from 'bcryptjs'
import jwt from 'jsonwebtoken'
import { UserPayload } from '../types'

export const hashPassword = async (password: string): Promise<string> => {
  const salt = await bcrypt.genSalt(10)
  return bcrypt.hash(password, salt)
}

export const comparePassword = async (password: string, hash: string): Promise<boolean> => {
  return bcrypt.compare(password, hash)
}

export const generateToken = (user: UserPayload): string => {
  return jwt.sign(user, process.env.JWT_SECRET || 'secret', { expiresIn: '24h' })
} 